package com.usian.article.controller;

import com.usian.api.article.ApAuthorApi;
import com.usian.article.service.ApAuthorService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements ApAuthorApi {
    @Autowired
    ApAuthorService apAuthorService;

    @PostMapping("save")
    @Override
    public ResponseResult saveAuthor(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.saveAuthor(apAuthor);
    }

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer userId) {
        return apAuthorService.findByUserId(userId);
    }

    @GetMapping("/findByName/{name}")
    @Override
    public ApAuthor findByName(@PathVariable("name") String name) {
        return apAuthorService.findByName(name);
    }

    /**
     * admin 远程调用，根据自媒体用户id查询作者对象
     * @param userId
     * @return
     */
    @GetMapping("/findByWmUserId/{id}")
    @Override
    public ApAuthor findByWmUserId(@PathVariable("id") Integer userId) {
        return apAuthorService.findByWmUserId(userId);
    }

    /**
     * user 远程调用 根据id查询用户name
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id")Integer id) {
        return apAuthorService.getById(id);
    }
}
